<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *会员列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$params=array('merchid'=>$_SESSION['onemerchid'],'type'=>0);
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$list=pdo_getslice('jy_scrm_sale_game',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=array('username'=>$item['username'],'avatar'=>$item['avatar'],'nickname'=>$item['nickname']);
			$item['url']=custom_url('jy_merchscrm/sale.liebian/detail/id='.$item['id'],true);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['status']=array('未开始','进行中','已结束');
	$return['workers']=pdo_getall('jy_scrm_worker',array('uniacid'=>$_SESSION['uniacid']),array('id','name'),'id');
	exi($return);
}
$steps=array('活动信息','活动奖品','高级设置','活动海报','活动欢迎语');
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	$return['sharemid']=intval($_RQ['fromuser']);
	if($id){
		$item=pdo_get('jy_scrm_sale_game',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		$item['starttime'] =$item['starttime']?date('Y/m/d H:i',$item['starttime']):'';
		$item['endtime'] =$item['endtime']?date('Y/m/d H:i',$item['endtime']):'';
	}else{
		exi('请选择活动！','error');
	}
	if($_SESSION['openid'] && $_SESSION['container']=='wxwork'){
		model('jy_scrm/member')->up_member_mid($_SESSION['openid']);
	}
	$item['red_set']=json_decode($item['red_set'],true);
	$item['poster_data']=$item['poster_data']?json_decode($item['poster_data'],true):array('data'=>$this->poster_datademo,'image'=>'../addons/jy_scrm/resource/images/poster_bg.png');
	$return['item']=$item;
	$params=array('uniacid'=>$_SESSION['uniacid'],'gameid'=>$id,'sharemid'=>$_SESSION['uid']);
	$return['allnum']=pdo_count('jy_scrm_sale_gamelog',$params,'id');
	$params['status']=1;
	$return['zulinum']=pdo_count('jy_scrm_sale_gamelog',$params,'id');
	$return['member']=cfc('core')->member_show($_SESSION['uid']);
	$return['poster']=model('jy_scrm/poster')->get_poster(0,$id);
	$return['params']=array('id'=>$id);
	$return['prize_sendtype']=array('活动期间','活动结束');
	$return['get_sextype']=array('不限制','仅男性参与','仅女性参与','未知');
	$return['get_areatype']=array('不限制','部分地区参与');
	$return['prize_type']=array('实物','红包');
	$return['datatypes']=$this->poster_datatypes;
	$return['datademo']=array('data'=>$this->poster_datademo,'image'=>'../addons/jy_scrm/resource/images/poster_bg.png');
	$return['datapushs']=$this->poster_datapushs;
	$sharelink='jy_merchscrm/sale.liebian//fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
				'title'=>$item['share_title']?:'呼朋唤友，免费拿奖品！',
				'desc'=>$item['share_desc']?:'好友，你可以给我打个Call吗？',
				'link'=>custom_url($sharelink,true),
				'imgUrl'=>$item['share_image']?tomedia($item['share_image']):tomedia('../addons/jy_scrm/resource/images/share.png')
	);
	set_html('title',$item['title']);
	exi($return);
}
if($_RQ['op']=='get_sharelist'){
	//分享助力
	$id=$_RQ['id'];
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'gameid'=>$id,'sharemid'=>$_SESSION['uid']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['num']?:20;
	$total='';
	$list=pdo_getslice('jy_scrm_sale_gamelog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['member']['avatar']=tomedia($item['member']['avatar']);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		}
	}
	$return['allnum']=pdo_count('jy_scrm_sale_gamelog',$params,'id');
	$params['status']=1;
	$return['zulinum']=pdo_count('jy_scrm_sale_gamelog',$params,'id');
	$return['list']=$list?:array();
	exi($return);
}
if($_RQ['op']=='zuli'){
	$post=get_postdata();
	$id=intval($post['id']);
	$sharemid=intval($post['sharemid']);
	model('jy_scrm/sale')->add_sharelog($id,$sharemid);
	exi('助力成功！');	
}